<include file="Public/min-header" />
<div class="wrapper">
    <include file="Public/breadcrumb" />
    <section class="content">
        <div class="container-fluid">
            <div class="pull-right">
                <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="返回"><i class="fa fa-reply"></i></a>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i>订单基本信息</h3>
                </div>
                <div class="panel-body">
                    <form method="post" action="{:U('Admin/Order/addOrder')}" id="order-add">
                        <div class="tab-pane">
                            <table class="table table-bordered">
                                <tbody>
                                    <tr>
                                        <td class = "text-right">用户名:</td>
                                        <td>
                                            <div class="form-group ">
                                                <div class="col-xs-2">
                                                    <input name="user_name" id="user_name" class="form-control" value="" placeholder="手机搜索" />
                                                </div>
                                                <div class="col-xs-2">
                                                    <select name="user_id" id="user_id" class="form-control">
                                                        <option value="0">匿名用户</option>
                                                    </select>
                                                </div>
                                                <div class="col-xs-2">
                                                    <button class="btn btn-info" type="button" onclick="searchUser();"><i class="ace-icon fa fa-search bigger-110"></i>搜索</button>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">收货人:</td>
                                        <td>
                                            <div class="form-group ">
                                                <div class="col-xs-2">
                                                    <input name="consignee" id="consignee" value="{$order.consignee}" class="form-control" placeholder="收货人名字" />
                                                </div>
                                                <div class="col-xs-2">
                                                    <span id="err_consignee" style="color:#F00; display:none;">收货人名字不能为空</span>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">地址:</td>
                                        <td>
                                            <div class="form-group ">
                                                <div class="col-xs-2">
                                                    <select onchange="get_city(this)" id="province" name="province" class="form-control">
                                                        <option value="0">选择省份</option>
                                                        <volist name="province" id="vo">
                                                            <option value="{$vo.id}">{$vo.name}</option>
                                                        </volist>
                                                    </select>
                                                </div>
                                                <div class="col-xs-2">
                                                    <select onchange="get_area(this)" id="city" name="city" class="form-control">
                                                        <option value="0">选择城市</option>
                                                        <volist name="city" id="vo">
                                                            <option value="{$vo.id}">{$vo.name}</option>
                                                        </volist>
                                                    </select>
                                                </div>
                                                <div class="col-xs-2">
                                                    <select id="district" name="district" class="form-control">
                                                        <option value="0">选择区域</option>
                                                        <volist name="area" id="vo">
                                                            <option value="{$vo.id}">{$vo.name}</option>
                                                        </volist>
                                                    </select>
                                                </div>
                                                <div class="col-xs-3">
                                                    <input name="address" id="address" value="{$order.address}" class="form-control" placeholder="详细地址" />
                                                </div>
                                                <div class="col-xs-2">
                                                    <span id="err_address" style="color:#F00; display:none;">请完善收货地址</span>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">手机:</td>
                                        <td>
                                            <div class="form-group ">
                                                <div class="col-xs-2">
                                                    <input name="mobile" id="mobile" value="{$order.mobile}" class="form-control" placeholder="收货人联系电话" />
                                                </div>
                                                <div class="col-xs-2">
                                                    <span id="err_mobile" style="color:#F00; display:none;">收货人电话不能为空</span>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">配送物流</td>
                                        <td>
                                            <div class="form-group ">
                                                <div class="col-xs-2">
                                                    <select id="shipping" name="shipping" class="form-control">
                                                        <volist name="shippingList" id="shipping">
                                                            <option <if condition="$order[shipping_code] eq $shipping[code]">selected</if> value="{$shipping.code}" >{$shipping.name}</option>
                                                        </volist>
                                                    </select>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">支付方式</td>
                                        <td>
                                            <div class="form-group ">
                                                <div class="col-xs-2">
                                                    <select id="payment" name="payment" class="form-control">
                                                        <volist name="payment_list" id="payment">
                                                            <option <if condition="$order[pay_code] eq $payment[code]">selected</if> value="{$payment.code}" >{$payment.name}</option>
                                                        </volist>
                                                    </select>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">发票抬头:</td>
                                        <td>
                                            <div class="form-group ">
                                                <div class="col-xs-4">
                                                    <input name="invoice_title" value="{$order.invoice_title}" class="form-control" placeholder="发票抬头" />
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">添加商品:</td>
                                        <td>
                                            <div class="form-group">
                                                <div class="col-xs-2">
                                                    <a class="btn btn-primary" href="javascript:;" onclick="selectGoods()"><i class="fa fa-search"></i>添加商品</a>
                                                </div>
                                                <div class="col-xs-2">
                                                    <span id="err_goods" style="color:#F00; display:none;">请添加下单商品</span>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">商品:</td>
                                        <td>
                                            <div class="form-group ">
                                                <div class="col-xs-10" id="goods_td">
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">管理员备注:</td>
                                        <td>
                                            <div class="form-group ">
                                                <div class="col-xs-4">
                                                    <textarea style="width:440px; height:150px;" name="admin_note" class = "form-control">管理员添加订单</textarea>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        <input type="hidden" name="id" value="{$order.order_id}">
                        <button class="btn btn-info" type="button" onclick="checkSubmit()">
                            <i class="ace-icon fa fa-check bigger-110"></i> 保存
                        </button>
                    </form>
                    <script>
                    function checkSubmit() {
                        $("span[id^='err_']").each(function() {
                            $(this).hide();
                        });

                        ($.trim($('#consignee').val()) == '') && $('#err_consignee').show();
                        ($.trim($('#province').val()) == '') && $('#err_address').show();
                        ($.trim($('#city').val()) == '') && $('#err_address').show();
                        ($.trim($('#district').val()) == '') && $('#err_address').show();
                        ($.trim($('#address').val()) == '') && $('#err_address').show();
                        ($.trim($('#mobile').val()) == '') && $('#err_mobile').show();
                        ($("input[name^='goods_id']").length == 0) && $('#err_goods').show();

                        if ($("span[id^='err_']:visible").length > 0)
                            return false;

                        $('#order-add').submit();
                    }
                    </script>
                </div>
            </div>
        </div>
    </section>
</div>
<script>
// 搜索用户 
function searchUser() {
    var user_name = $('#user_name').val();
    if ($.trim(user_name) == '')
        return false;

    $.ajax({
        type: "POST",
        url: "/index.php?m=Admin&c=User&a=searchUser",
        data: {
            search_key: $('#user_name').val()
        },
        success: function(data) {
            data = data + '<option value="0">匿名用户</option>';
            $('#user_id').html(data);
        }
    });
}


/* 用户订单区域选择 */
$(document).ready(function() {
        /*
         $('#province').val({$order.province});
         $('#city').val({$order.city});
         $('#district').val({$order.district});
         $('#shipping_id').val({$order.shipping_id});
         */
    })
    // 选择商品
function selectGoods() {
    var url = "{:U('Admin/Order/searchGoods')}";
    layer.open({
        type: 2,
        title: '选择商品',
        shadeClose: true,
        shade: 0.8,
        area: ['60%', '60%'],
        content: url,
    });
}
// 选择商品返回
function call_back(table_html) {
    $('#goods_td').empty().html('<table class="table table-bordered">' + table_html + '</table>');
    layer.closeAll('iframe');
}
</script>
</body>

</html>
